Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Daita Support on iOS #6673

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

buggmagnet
Copy link
Contributor

@buggmagnet buggmagnet commented Aug 23, 2024

This PR adds Daita support on iOS, it looks big, but it's only because many files / APIs have been renamed to match more closely what happens behind the scenes, notably :

  • Most PostQuantum* have been renamed EphemeralPeer*
  • Only 1 extra test has been written so far testEphemeralPeerExchangeSuccessWhenDaitaNegotiationStarts, more are coming
  • Daita functions mostly like negotiating a post quantum key, so the architecture remains unchanged

This change is Reviewable

@buggmagnet buggmagnet added the iOS Issues related to iOS label Aug 23, 2024
@buggmagnet buggmagnet self-assigned this Aug 23, 2024
Copy link

linear bot commented Aug 23, 2024

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 56 of 56 files at r1, all commit messages.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @buggmagnet)


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 100 at r1 (raw file):

) {
    guard let rawPostQuantumKeyReceiver else { return }
    let postQuantumKeyReceiver = Unmanaged<EphemeralPeerReceiver>.fromOpaque(rawPostQuantumKeyReceiver)

Nit: emphemeralKeyReceiver


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 110 at r1 (raw file):

    }

    // If there is a pre-shared key, an ephemeral peer was negotiated with Post Quantum options

Is it always true that the lack of a preshared key is daita? I guess it is for now, but what happens if we add new tech that uses the same infrastructure? I think EphemeralPeer is a fine collective term to use here, but I wonder if the implementation where the lack of a certain element guarantees one thing or the other.


ios/MullvadTypes/Protocols/EphemeralPeerReceiving.swift line 2 at r1 (raw file):

//
//  PostQuantumKeyReceiving.swift

Nit: EphemeralPeerReceiving


ios/MullvadVPN/TunnelManager/TunnelState.swift line 55 at r1 (raw file):

    case connecting(SelectedRelays?, isPostQuantum: Bool)

    // TODO: Add information here to support Daita ???

To be continued?


ios/MullvadVPN/TunnelManager/TunnelState.swift line 116 at r1 (raw file):

            "error state: \(blockedStateReason)"
        case let .negotiatingEphemeralPeer(tunnelRelays, _):
            // TODO: Handle Daita and PQ here

To be continued?


ios/MullvadVPN/TunnelManager/TunnelState+UI.swift line 52 at r1 (raw file):

            }

        // TODO: How to Handle Daita here ?

This part can be delegated to daita tickets related to UI. That should still be noted here I think.


ios/PacketTunnelCore/Actor/ObservedState+Extensions.swift line 19 at r1 (raw file):

        case .connecting:
            "Connecting"
        // TODO: Handle Daita here ?

I guess so. We should proably check the ObservedConnectionState is daita and/or post quantum is used and return an approriate name.


ios/PacketTunnelCore/Actor/PacketTunnelActor+PostQuantum.swift line 101 at r1 (raw file):

            // wireguard-go will only turn on daita for the entry peer,
            // so pass the daita configuration to the exit peer for consistency

What's meant here by passing config to exit for consistency? Can't see how the comment reflects the code.


ios/PacketTunnelCore/Actor/PacketTunnelActorCommand.swift line 76 at r1 (raw file):

            case .switchKey:
                return "switchKey"
            // TODO: Handle Daita here ???

Perhaps more cases are needed to handle this. We shouldn't just leave the Todo though.

Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @rablador)


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 110 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Is it always true that the lack of a preshared key is daita? I guess it is for now, but what happens if we add new tech that uses the same infrastructure? I think EphemeralPeer is a fine collective term to use here, but I wonder if the implementation where the lack of a certain element guarantees one thing or the other.

I was debating whether I wanted to add a different FFI that specifies Daita only peers, but would increase a lot the cyclomatic complexity for virtually no benefits.

There cannot be a situation where we get an ephemeral peer that has an invalid preshared key, since the key is attached to the ephemeral peer when we request it.


ios/MullvadVPN/TunnelManager/TunnelState.swift line 55 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

To be continued?

Yes, there are a lot of TODO comments that will be fixed with working on the UI.


ios/PacketTunnelCore/Actor/PacketTunnelActor+PostQuantum.swift line 101 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

What's meant here by passing config to exit for consistency? Can't see how the comment reflects the code.

Oh that's a good catch, I had a previous design where I was passing the Daita configuration in the ConfigurationBuilder instead, and that's a relic of that past. I will delete the comment.

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from e84a7a7 to 5197342 Compare August 27, 2024 14:44
Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 45 of 56 files reviewed, 7 unresolved discussions (waiting on @rablador)


ios/PacketTunnelCore/Actor/PacketTunnelActorCommand.swift line 76 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

Perhaps more cases are needed to handle this. We shouldn't just leave the Todo though.

I think we can safely remove this TODO here 🤔

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from 5197342 to 28dfe0d Compare August 28, 2024 12:32
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 10 of 11 files at r2, 4 of 4 files at r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @buggmagnet)


ios/MullvadVPN/TunnelManager/TunnelState.swift line 55 at r1 (raw file):

Previously, buggmagnet wrote…

Yes, there are a lot of TODO comments that will be fixed with working on the UI.

I think we should address them as such then. Right now it looks like this PR still has TODOs rather than delegating them to another PR.

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from 28dfe0d to 6b67700 Compare September 3, 2024 06:57
Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 52 of 56 files reviewed, 4 unresolved discussions (waiting on @rablador)


ios/MullvadVPN/TunnelManager/TunnelState+UI.swift line 52 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

This part can be delegated to daita tickets related to UI. That should still be noted here I think.

Done.


ios/PacketTunnelCore/Actor/ObservedState+Extensions.swift line 19 at r1 (raw file):

Previously, rablador (Jon Petersson) wrote…

I guess so. We should proably check the ObservedConnectionState is daita and/or post quantum is used and return an approriate name.

This is used for debugging purposes only, so it should be fine. I've removed the comment, we'll quickly see whether I was wrong to or not :D

Copy link
Collaborator

@mojganii mojganii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 52 of 56 files reviewed, 6 unresolved discussions (waiting on @buggmagnet and @rablador)


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 81 at r2 (raw file):

}

/// End sequence of a quantum-secure pre shared key exchange.

I believe this part should also be updated.


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 85 at r2 (raw file):

/// This FFI function is called by Rust when an ephemeral peer negotiation succeeded or failed.
/// When both the `rawPresharedKey` and the `rawEphemeralKey` are raw pointers to 32 bytes data arrays,
/// the quantum-secure key exchange is considered successful.

Key exchanging is taking place regardless of weather it's PQ or Daita. then I believe having quantum secure is forbidden.

Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 52 of 56 files reviewed, 6 unresolved discussions (waiting on @mojganii and @rablador)


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 81 at r2 (raw file):

Previously, mojganii wrote…

I believe this part should also be updated.

Good catch !


ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift line 85 at r2 (raw file):

Previously, mojganii wrote…

Key exchanging is taking place regardless of weather it's PQ or Daita. then I believe having quantum secure is forbidden.

Yes, but that paragraph is still correct, since we still need to document the PQ only case

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 51 of 56 files reviewed, 7 unresolved discussions (waiting on @buggmagnet, @mojganii, and @rablador)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

            let token = runtime.packet_tunnel.tcp_connection.clone();

            let tokio_handle = match crate::mullvad_ios_runtime() {

Why move this function here from mod.rs?

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 51 of 56 files reviewed, 8 unresolved discussions (waiting on @buggmagnet, @mojganii, and @rablador)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 142 at r5 (raw file):

            match Self::ios_tcp_client(self.packet_tunnel.clone()).await {
                Ok(result) => result,

Unnecessary whitespace change.

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 11 files at r2.
Reviewable status: 51 of 56 files reviewed, 8 unresolved discussions (waiting on @buggmagnet, @mojganii, and @rablador)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 56 files at r1, 1 of 11 files at r2.
Reviewable status: 51 of 56 files reviewed, 8 unresolved discussions (waiting on @buggmagnet, @mojganii, and @rablador)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 51 of 56 files reviewed, 9 unresolved discussions (waiting on @buggmagnet, @mojganii, and @rablador)


ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved line 17 at r5 (raw file):

      "location" : "https://github.com/mullvad/wireguard-apple.git",
      "state" : {
        "revision" : "fb9a34f15e47b167866af3257a8dcc9901d9e7c1"

This is an outdated commit now.

Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 51 of 56 files reviewed, 9 unresolved discussions (waiting on @mojganii, @pinkisemils, and @rablador)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

Why move this function here from mod.rs?

We used to pass the TokioHandle as part of run_post_quantum_psk_exchange which made clippy complain that we were passing too many parameters, I've moved creating (or getting) the runtime to just before we need it, It should still fail the same way as before if we can't get a runtime .


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 142 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

Unnecessary whitespace change.

We should agree on using a rust formatter then

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 4 files at r4, 1 of 1 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @buggmagnet, @mojganii, and @pinkisemils)

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from e3eac94 to 666b680 Compare September 4, 2024 09:04
rablador
rablador previously approved these changes Sep 4, 2024
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @buggmagnet, @mojganii, and @pinkisemils)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @buggmagnet and @mojganii)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

Previously, buggmagnet wrote…

We used to pass the TokioHandle as part of run_post_quantum_psk_exchange which made clippy complain that we were passing too many parameters, I've moved creating (or getting) the runtime to just before we need it, It should still fail the same way as before if we can't get a runtime .

Fair. Interesting that this passed the CI last time. I'd prefer to keep this function free from that call, but if clippy is complaining, then we could also stuff all of the peer exchange args into a struct instead.


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 142 at r5 (raw file):

Previously, buggmagnet wrote…

We should agree on using a rust formatter then

We are using a rust formatter, and the whitespace is not being introduced by the formatter.

Copy link
Contributor Author

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @mojganii and @pinkisemils)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

Fair. Interesting that this passed the CI last time. I'd prefer to keep this function free from that call, but if clippy is complaining, then we could also stuff all of the peer exchange args into a struct instead.

Yes, I'm not super happy about this either. I think if we want to revisit this code in the future, we should take the opportunity to refactor a bit to make it cleaner


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 142 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

We are using a rust formatter, and the whitespace is not being introduced by the formatter.

I've ran cargo fmt but it didn't change anything. I probably added some extra lines when I was refactoring. I'll remove the extra line.


ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved line 17 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

This is an outdated commit now.

Done.

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from 0fc3868 to 7d98980 Compare September 4, 2024 11:37
@rablador rablador requested a review from pinkisemils September 4, 2024 13:57
rablador
rablador previously approved these changes Sep 4, 2024
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r8, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @buggmagnet, @mojganii, and @pinkisemils)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @buggmagnet and @mojganii)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

Previously, buggmagnet wrote…

Yes, I'm not super happy about this either. I think if we want to revisit this code in the future, we should take the opportunity to refactor a bit to make it cleaner

We can stuff the extra parameters in a struct today and move the instantiation of the tokio handle back to where it was before.

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @buggmagnet and @mojganii)


mullvad-ios/src/post_quantum_proxy/ios_runtime.rs line 42 at r5 (raw file):

Previously, pinkisemils (Emīls Piņķis) wrote…

We can stuff the extra parameters in a struct today and move the instantiation of the tokio handle back to where it was before.

Just to be clear, clippy lints are not there to be appeased, they are there to force us to think of a better design. I don't think moving a call between functions is the path to a better design in this case.

@buggmagnet buggmagnet force-pushed the change-packettunnel-to-support-daita-ios-776 branch from 7d98980 to f8638f9 Compare September 5, 2024 12:31
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r9, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @buggmagnet and @mojganii)

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r10, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @buggmagnet and @mojganii)

Copy link
Collaborator

@pinkisemils pinkisemils left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r10, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @buggmagnet and @mojganii)

@pinkisemils pinkisemils force-pushed the change-packettunnel-to-support-daita-ios-776 branch from 166e7ef to 678f653 Compare September 6, 2024 10:37
@pinkisemils pinkisemils merged commit e015870 into main Sep 6, 2024
48 of 54 checks passed
@pinkisemils pinkisemils deleted the change-packettunnel-to-support-daita-ios-776 branch September 6, 2024 10:59
Copy link

github-actions bot commented Sep 6, 2024

🚨 End to end tests failed. Please check the failed workflow run.

@MrChocolatine MrChocolatine mentioned this pull request Sep 13, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants